package ms.jasim.framework;

import java.util.ArrayList;

class JasimServiceProvider implements IServiceProvider {

	private ArrayList<Object> services;
	
	public JasimServiceProvider() {
		services = new ArrayList<Object>();
	}
	
	@Override
	public void addService(Object svcInstance) {
		if (svcInstance != null && !services.contains(svcInstance))
			services.add(svcInstance);
	}

	@SuppressWarnings("unchecked")
	@Override
	public <T> T getService(Class<T> svcContract) {
		for (Object obj : services)
			if (svcContract.isAssignableFrom(obj.getClass()))
				return (T) obj;
		return null;
	}

	
	@Override
	public void removeService(Object service) {
		services.remove(service);
	}

}
